<?php
require_once 'Zend/Controller/Action.php';

class ActivityController extends App_Zend_Controller_Action_Shop{
	public function init(){
		
	}
	public function indexAction(){
		$this->view->noLongBanner = 1;
		$today = date("d");
		$this->view->today = $today;
		
	}
	public function verifyAction(){
		
	}
	public function getcodeAction(){
		$to_email = $this->getRequest()->getParam('email');
		if(!empty($to_email)){
			$code = md5('newjerseysoccer'.$to_email);
		}
		
		$config = array('auth' => 'login',
				'username' => 'service@newjerseysoccer.net',
				'password' => 'qa1234'
		);
		$transport = new Zend_Mail_Transport_Smtp('smtp.exmail.qq.com',$config);
		$mail = new Zend_Mail();
		$mail->addTo($to_email,$to_email);
		$mail->setFrom('service@newjerseysoccer.net', 'service@newjerseysoccer.net');
		$mail->setSubject('shop code');
		$mail->setBodyText($code);
		$mail->send($transport);
		
		$data['email']=$to_email;
		$data['code']=$code;
		$buycodeModel = new CBuycode();
		$db = $buycodeModel->getAdapter();
		$where = $db->quoteInto('email = ?',$to_email);
		$row = $buycodeModel->fetchRow($where);
		if(empty($row)){
			$buycodeModel->insert($data);
			echo "success";
		}else{
			echo "false";
		}
		exit();
		//发送邮件,将数据写入表zcshop_buycode
	}
	public function showproductAction(){
		$this->view->noLongBanner = 1;
		$email = $this->getRequest()->getParam('getcodeemail');
		$code = $this->getRequest()->getParam('codenumber');
		$buycodeModel = new CBuycode();
		$db = $buycodeModel->getAdapter();
		$where = $db->quoteInto('email = ?',$email) . $db->quoteInto('AND code = ?',$code);
		$row = $buycodeModel->fetchRow($where); 
		if(!empty($row)){
			$today = date("d");
			$productModel = new CProduct();
			$day11 = "1250,1251,1569,2590,2494,2493,2431,1539,2298,1549,1988,1538,2418,1532,2308,1527,1259,1258,2429,2307,1521,2588,2444";
			$day12 = "2570,2581,2421,1887,2211,2606,1560,1554,2424,2519,2520,2409,1552,2404,2427,1752,20572425,1989,2419,2430,1566,1477,1938,1976,1944,2423,2309,2593,2416,1874,2561";
			if($today==11){
				$allproduct = $productModel->getAllProduct($day11);
			}elseif($today==12){
				$allproduct = $productModel->getAllProduct($day12);
			}else{
				$allproduct = "";

				
			}
			$this->view->allproduct = $allproduct;
			$this->view->today = $today;
			
		}else{
			throw new ErrorException('请确认Email和code是否正确！');
		}
		
		
		//从表zcshop_buycode中查询是否有对应数据，如果有跳转到活动产品页面
	}
}

?>